#!/usr/bin/make -f

export INSTALL_MOD_DIR:=extra

PACKAGE_PRE_NAME := sonic-platform-mitac
KVERSION   ?= $(shell uname -r)
KERNEL_SRC :=  /lib/modules/$(KVERSION)
MOD_SRC_DIR:= $(shell pwd)
MODULE_DIRS:= ly1200-32x

%:
		dh $@

override_dh_auto_build:
	(for mod in $(MODULE_DIRS); do \
		make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \
	done)

override_dh_auto_install:
	(for mod in $(MODULE_DIRS); do \
			dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}\
				$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
			dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin;\
			cp $(MOD_SRC_DIR)/$${mod}/modules/*.ko \
					debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
			mkdir -p debian/$(PACKAGE_PRE_NAME)-$${mod}/opt; \
			cp -rfL $(MOD_SRC_DIR)/$${mod}/opt/* \
					debian/$(PACKAGE_PRE_NAME)-$${mod}/opt; \
			mkdir -p debian/$(PACKAGE_PRE_NAME)-$${mod}/etc/init.d; \
			cp -rfL $(MOD_SRC_DIR)/$${mod}/etc/* \
					debian/$(PACKAGE_PRE_NAME)-$${mod}/etc; \
	done)

override_dh_usrlocal:

override_dh_clean:
	dh_clean
	(for mod in $(MODULE_DIRS); do \
			make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \
	done)

